package com.frank.work.task;

import com.frank.work.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import java.util.Optional;

/**
 * @author 小石潭记
 * @date 2021/12/21 11:15
 * @Description: ${todo}
 */
@Slf4j
@Component("EmailGroupNodeTask")
public class EmailGroupNodeTask extends AbstractPipelineNodeTask {

    @Override
    public Object deal(Object args, PipelineNode pipelineNode) {
        if (args instanceof Optional) {
            Optional optional = (Optional) args;
            return handleTask((BasicInfo) optional.get());
        }
        return handleTask((BasicInfo) args);
    }

    /**
     * 处理业务逻辑
     * @param basicInfo
     */
    private Optional<BasicInfo> handleTask(BasicInfo basicInfo) {
        Email email = new Email();
        email.setOriginalAddress("810464826@qq.com");
        email.setTargetAddress("875403358@qq.com");
        email.setSender("小石潭记");
        email.setReceiver("陋室铭");
        basicInfo.setEmail(email);
        log.info("最后节点邮件信息补充完成，最终的basic信息:{}", basicInfo);
        return Optional.ofNullable(basicInfo);
    }
}
